package com.imu.purse.modules.app.dao;

import java.util.List;

import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import com.imu.core.base.BaseMapper;
import com.imu.purse.modules.app.entity.ImuUserEntity;

/**
 * 用户信息
 * @author sunhongwei
 * @email sunhongwei@jshijian.com
 * @date 2018-03-21 10:11:22
 * Copyright (c) 2017 武汉极时间科技有限公司 版权所有 
 * Jshijian aloha CO.,LTD. All Rights Reserved. 
 */
public interface ImuUserMapper extends BaseMapper<ImuUserEntity>
{
	/**
     * 分页查询
     * @return
     */
	@Select({
		"<script>",
		    "SELECT id,",
					"nick_name, ",
					"gender, ",
					"birthday, ",
					"address, ",
					"state, ",
					"photo, ",
					"summary, ",
					"phone, ",
					"user_name, ",
					"real_name, ",
					"card_no, ",
					"ident_code, ",
					"auth_state, ",
					"pwd, ",
					"pay_pwd, ",
					"on_line, ",
					"bank_no, ",
					"bank_name, ",
					"bank_account, ",
					"bank_branch, ",
					"user_create, ",
					"time_create, ",
					"user_update, ",
					"time_update",
		    "FROM imu_user ",
		    "WHERE 1=1",
		    "<when test = 'timeUpdate != null'>",
		    	"AND time_update &gt;= #{timeUpdate}",
		    "</when>",
		    "<when test = 'timeCreate != null'>",
				"AND time_create &lt;= #{timeCreate}",
			"</when>",
			"<when test = 'phone!= null'>",
			  "AND phone = #{phone}",
		"</when>",
		    "ORDER BY time_create DESC",
    	"</script>"
	})
    public List<ImuUserEntity> findByPage(final ImuUserEntity entity);	
	@Select({
		"<script>",
		    "update imu_user set",
					"MONEY= MONEY+#{money},",
					"LOCK_MONEY= LOCK_MONEY+#{money}",
		    "WHERE id = #{id}",
    	"</script>"
	})
	public int updates(final ImuUserEntity entity);
	
	@Select({
		"select id from imu_user where phone = #{phone}"
	}
	)
	public Long findIdByPhone(final String phone);
	
	@Select({
		"SELECT id,",
		   "nick_name, ",
			"gender, ",
			"birthday, ",
			"address, ",
			"state, ",
			"photo, ",
			"summary, ",
			"phone, ",
			"user_name, ",
			"real_name, ",
			"card_no, ",
			"ident_code, ",
			"auth_state, ",
			"pwd, ",
			"pay_pwd, ",
			"on_line, ",
			"bank_no, ",
			"bank_name, ",
			"bank_account, ",
			"bank_branch, ",
			"user_create, ",
			"time_create, ",
			"user_update, ",
			"time_update, ",
			"INTER_PHONE",
          "FROM imu_user ",
           " WHERE phone=#{phone}",
	})
	
	public ImuUserEntity selectUserInfoByPhone(String phone);
}
